<template>
  <article class="post-item">
    <div class="card-img">
      <router-link :to="'/article/' + postItem.id">
        <q-img
          class="image-wrapper"
          :src="
            !postItem.coverImg
              ? `https://api.ixiaowai.cn/gqapi/gqapi.php?t=${Math.random()}`
              : postItem.coverImg
          "
          style="height:100%"
        >
          <template v-slot:loading>
            <q-spinner-gears color="white" />
          </template>
        </q-img>
      </router-link>
    </div>
    <!-- 遮罩 -->
    <div class="post-item-wrapper">
      <span class="category">
        <router-link
          class="btn btn-primary btn-xs cat"
          :to="`/category/${encodeURIComponent(postItem.category)}`"
          >{{ postItem.category }}</router-link
        >
      </span>
      <p
        style=" display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 5;overflow:hidden;text-overflow: ellipsis;"
      >
        {{ postItem.degest }}
      </p>
    </div>

    <div class="post-item-content">
      <div class="post-item-tags">
        <template v-for="tag in postItem.tagNames">
          <router-link
            :key="tag"
            class="text-white"
            :to="`/tag/${encodeURIComponent(tag)}`"
            >{{ tag }}</router-link
          >
        </template>
      </div>

      <router-link :to="'/article/' + postItem.id">
        <h2 class="item-title">
          <router-link :to="'/article/' + postItem.id" class="cu-text">
            {{ postItem.title }}
          </router-link>
        </h2>
        <p class="item-description">{{ postItem.degest }}</p>
      </router-link>
      <p class="item-meta text-grey-9">
        <span class="time">
          <q-icon name="mdi-clock-time-three-outline" class="text-purple-5" />

          {{ postItem.createdAt | timeAgo }}
        </span>
        <span class="views text-grey-9">
          <q-icon
            name="mdi-cursor-default-click-outline"
            class="text-green-5"
          />
          {{ postItem.viewNum }}
        </span>
        <span class="comments text-grey-9">
          <router-link :to="'/article/' + postItem.id">
            <q-icon name="mdi-comment-processing-outline" class="text-blue-5" />
            {{ postItem.commentNum }}
          </router-link>
        </span>
        <span class="like text-grey-9">
          <q-icon name="mdi-cards-heart" class="text-red" />
          {{ postItem.likes }}
        </span>

        <span class="category text-grey-9">
          <router-link
            class="btn btn-primary btn-xs cat"
            :to="`/category/${encodeURIComponent(postItem.category)}`"
          >
            <q-icon name="mdi-order-bool-ascending" class="text-grey-9" />

            {{ postItem.category }}
          </router-link>
        </span>
      </p>
    </div>
  </article>
</template>

<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator';
import { Article } from 'src/models/article';

@Component({})
export default class postItem extends Vue {
  @Prop({ type: Object, required: true }) readonly postItem!: Article;

  get defaultImg(): string {
    return this.$store.state.global.defaultImg;
  }

  get language(): string {
    return this.$store.state.global.language;
  }
}
</script>

<style lang="scss" scoped>
.post-item {
  box-shadow: 10px 10px 10px var(--card-bg);
  .card-img {
    overflow: hidden;
    .image-wrapper {
      transition: 0.5s;
    }
  }
  &:hover {
    box-shadow: 10px 10px 10px var(--text-black);
    .card-img .image-wrapper {
      transform: scale(1.2);
    }
  }

  .post-item-wrapper {
    display: none;
    @include absPercent100();
    padding: 40px 28px;
    overflow: hidden;
    transition: $transition-time-slow;
    p {
      display: none;
      font-size: 13px;
      text-indent: 20px;
      font-weight: 500;
    }
  }
  .post-item-content {
    padding: 10px 20px;
    background-color: var(--card-bg);
    position: relative;
    width: 100%;
    .item-title {
      margin: 0.5rem 1.5rem;
      margin-top: 0;
      -webkit-line-clamp: 2;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      overflow: hidden;
      a {
        word-break: break-all;
      }
    }
    .item-description {
      padding: 0.5rem;
      font-size: 0.8rem;
      -webkit-line-clamp: 3;
      text-indent: 20px;
      color: #606266;
    }
    .post-item-tags {
      margin-bottom: 0.5rem;
      min-height: 30px;
      > a {
        display: block;
        padding: 2px 5px;
        font-size: 10px;
        display: inline-block;
        position: relative;
        margin: 5px;
        background: linear-gradient(90deg, #ff9800 0, #eb5055 100%);
        border-radius: 3px;
        color: var(--text-white);
        // &::before {
        //   @include transparentbtn;
        // }

        &:nth-child(3n-2) {
          background: linear-gradient(to right, #ec008c, #fc6767);
        }
        &:nth-child(3n-1) {
          background: linear-gradient(to right, #8e54e9, #b433ff);
        }
      }
    }
  }
}

.list-container {
  .post-item {
    min-height: 130px;
    display: flex;
    position: relative;
    margin: 20px 0;
    overflow: hidden;
    background-color: var(--card-bg);
    border-radius: 5px;

    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.2);
    // box-shadow: 10px 10px 10px var(--card-bg), -10px -10px 10px var(--card-bg);
    transition: all 0.3s;

    display: flex;
    .post-item-cover {
      img {
        @include absPercent100();
        max-width: 100%;

        filter: blur(50px) brightness(0.8);
        transform: scale(1.2);
        opacity: 1;
        transition: opacity 0.5s;
      }
    }

    .card-img {
      flex-basis: 50%;
      position: relative;

      img {
        transition: 0.5s;
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }
    &:nth-child(odd) {
      .card-img {
        &::after {
          content: '';
          height: 100%;
          position: absolute;
          top: 0;
          right: 0;
          display: block;
          box-shadow: 1px 1px 8px 21px $white;
          transform: skewX(6.5deg);
        }
      }
    }
    &:nth-child(even) {
      flex-direction: row-reverse;
      .card-img {
        &::after {
          content: '';
          height: 100%;
          position: absolute;
          top: 0;
          left: 0;
          display: block;
          box-shadow: 1px 1px 8px 21px $white;
          transform: skewX(-6.5deg);
        }
      }
    }

    .post-item-content {
      height: 100%;
      align-self: center;
      padding: 5px 10px;
      position: relative;

      .item-title {
        font-size: 15px;
        font-weight: 700;
      }
      .item-meta {
        height: 2em;
        line-height: 2em;
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        overflow: hidden;
        font-size: 12.432px;
        white-space: nowrap;
        text-overflow: ellipsis;

        span {
          margin-right: 5px;
          color: var(--text-light);
          a {
            color: var(--text-light);
          }
          i {
            color: var(--text-light);
          }
        }
        .category {
          &:hover {
            text-decoration: underline;
          }
        }
        // .category {
        //   color: #39c408;
        //   position: relative;
        //   > a {
        //     padding: 2px 5px;
        //     &::before {
        //       @include transparentbtn;
        //     }
        //   }
        // }
      }
    }
  }
}

.card-container {
  display: flex;
  flex-wrap: wrap;

  .post-item {
    display: flex;
    flex-basis: 30%;
    flex-wrap: wrap;
    margin: 10px;
    border-radius: 13px;
    box-shadow: 0 13px 15px rgba(31, 45, 61, 0.15);
    position: relative;
    overflow: hidden;
    .post-item-cover {
      display: none;
    }
    .card-img {
      width: 100%;
      height: 12rem;
      img {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        transition: $transition-time-slow;
      }
    }
    .post-item-content {
      padding: 10px 20px;
      .item-title {
        text-align: center;
        margin: 10px 0px;
      }
      .item-description {
        display: none;
      }
      .item-meta {
        padding: 0 10px;
        display: flex;
        justify-content: space-between;
        span {
          margin-right: 5px;
          i {
            color: var(--text-color-light);
          }
        }
        .category {
          display: none;
        }
      }
    }

    .post-item-wrapper {
      top: -100%;

      display: block;
      .category {
        position: absolute;
        right: -23px;
        top: 13px;
        font-size: 12px;
        margin-top: 5px;
        padding: 2px 8px 2px 12px;
        background: linear-gradient(to right, #eb3349, #f45c43);
        color: #fff;
        -webkit-transform: rotate(45deg);
        transform: rotate(45deg);
        a {
          color: #fff;
          display: inline-block;
          min-width: 86px;
          text-align: center;
          font-weight: 500;
          &::before,
          &::after {
            content: '';
            border-left: 3px solid transparent;
            border-right: 3px solid transparent;
            position: absolute;
            bottom: -3px;
            z-index: 20;
            border-top: 3px solid #f45c43;
          }
          &::before {
            left: 0;
          }
          &::after {
            right: 0;
          }
        }
        i {
          display: none;
        }
      }
    }
    &:nth-child(4n-1) {
      .post-item-wrapper > .category {
        background: linear-gradient(to right, #ec008c, #fc6767);
        a:before,
        a::after {
          border-top: 3px solid #ec008c;
        }
      }
    }

    &:nth-child(4n-2) {
      .post-item-wrapper > .category {
        background: linear-gradient(90deg, #ff9800 0, #eb5055 100%);
        a:before,
        a::after {
          border-top: 3px solid #ff9800;
        }
      }
    }

    &:nth-child(4n-3) {
      .post-item-wrapper > .category {
        background: linear-gradient(to right, #1d976c, #93f9b9);
        a:before,
        a::after {
          border-top: 3px solid #1d976c;
        }
      }
    }

    &:hover {
      cursor: pointer;
      .post-item-wrapper {
        background: rgba(0, 0, 0, 0.5);
        top: 0;
        > p {
          display: block;
          color: #fff;
        }
      }
      .card-img img {
        filter: blur(3px);
        transform: scale(1.2);
      }
    }
  }
}

@media screen and (min-width: 576px) and (max-width: 768px) {
  .list-container {
    .post-item {
      .card-img {
        flex-basis: 60%;
        position: relative;
      }
    }
  }
}
@media screen and (max-width: 576px) {
  .list-container {
    .post-item {
      flex-wrap: wrap;
      .card-img {
        flex-basis: 100%;
        position: relative;
        &:after {
          display: none !important;
        }
      }
    }
  }
}
</style>
